package com.yanq.liancar.activity;
/*
 *  @创建者     liyan
 *  @创建时间   2018/9/16  14:28
 *  @描述       ${TODO}
 */


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.TextView;

import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.vondear.rxtool.view.RxToast;
import com.yanq.liancar.R;
import com.yanq.liancar.activity.base.BaseToolbarActivity;
import com.yanq.liancar.bean.BaseBean;
import com.yanq.liancar.url.Config;
import com.yanq.liancar.util.Utils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SmallBOrderEvaluateActivity extends BaseToolbarActivity {
    @BindView(R.id.ratingbar)
    RatingBar ratingbar;
    @BindView(R.id.et_content)
    EditText etContent;
    @BindView(R.id.img_statu)
    ImageView imgStatu;
    @BindView(R.id.ll_niming)
    LinearLayout llNiming;
    @BindView(R.id.Release)
    TextView Release;

    private int ratingBarNum,orderID;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_small_b_orderevaluate);
        Utils.setStatusBar(this, true,false);
        ButterKnife.bind(this);
        mTvTitle.setText("评价");
        orderID=getIntent().getIntExtra("orderID",0);

        ratingbar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
            @Override
            public void onRatingChanged(RatingBar ratingBar, float v, boolean b) {
                ratingBarNum= (int) v;
            }
        });
    }

    @OnClick({R.id.ll_niming, R.id.Release})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_niming:
                break;
            case R.id.Release:
                okGoReleaseOrder();
                break;
        }
    }

    //发布评价
    private void okGoReleaseOrder() {
        OkGo.<String>post(Config.s + "llc/api/updateOrderRate")
                .tag(this)
                .params("orderid", orderID)
                .params("orderrate", etContent.getText().toString().trim())
                .params("star", ratingBarNum)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        Gson gson = new Gson();
                        BaseBean bean = gson.fromJson(response.body(), BaseBean.class);
                        if (bean.isIsSuccess()) {
                            RxToast.success(bean.getOutputMessage());
                            finish();
                        } else {
                            RxToast.error(bean.getOutputMessage());
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        RxToast.error("服务器连接错误");
                    }
                });
    }
}
